package com.bobby.web;

import com.bobby.pojo.Page;
import com.bobby.service.BookService;
import com.bobby.service.impl.BookServiceImpl;
import com.bobby.utils.JdbcUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * @Description TODO
 * @Date 2020/8/15 12:45
 * @Created wenjunpei
 */
public class ClientBookServlet extends BaseServlet {

    private BookService bookService = new BookServiceImpl();

    protected void page(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String pageNo = request.getParameter("pageNo");
        String pageSize = request.getParameter("pageSize");
        Page page = null;

        page = bookService.page(pageNo,pageSize);

        page.setUrl("client/bookServlet?action=page");
        request.setAttribute("page",page);
        request.getRequestDispatcher("/pages/client/index.jsp").forward(request,response);
    }

    protected void pageByPrice(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String pageNo = request.getParameter("pageNo");
        String pageSize = request.getParameter("pageSize");
        String min = request.getParameter("min");
        String max = request.getParameter("max");
        Page page = null;

        page = bookService.pageByPrice(pageNo,pageSize,min,max);

        StringBuilder stringBuilder = new StringBuilder("client/bookServlet?action=pageByPrice");
        if(min != null) {
            stringBuilder.append("&min=").append(min);
        }
        if(max != null) {
            stringBuilder.append("&max=").append(max);
        }
        page.setUrl(stringBuilder.toString());
        request.setAttribute("page",page);
        request.getRequestDispatcher("/pages/client/index.jsp").forward(request,response);
    }


}
